package Util;

import java.io.UnsupportedEncodingException;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import Model.NhaSanXuat;
@FacesConverter(forClass=NhaSanXuat.class)
public class ConveterNSX implements Converter{

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		try {
			arg2 = new String(arg2.getBytes("ISO-8859-1"),"utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Integer id = DAO.laynhasanxuat(arg2).getIdnhasanxuat();
		NhaSanXuat nsx = new NhaSanXuat();
		nsx.setTennhasanxuat(arg2);
		nsx.setIdnhasanxuat(id);
		return nsx;
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		NhaSanXuat nsx = (NhaSanXuat)arg2;
		return nsx.getTennhasanxuat();
	}

}
